/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.academy.model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import ar.uba.fi.posgrado.common.model.AbstractDomainObject;

/**
 * Acta
 * 
 * @author ariel.piechotka
 * 
 */

@Entity
@Table(name = "ACTA")
@SuppressWarnings("serial")
public class AcademicRecord extends AbstractDomainObject {

	public static final Short MAX_QTY_STUDENTS = 20;

	public static final Short DEFAULT_QTY_STUDENTS = 10;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_MATERIA", nullable = false)
	private Subject subject;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_DOCENTE", nullable = false)
	private Teacher teacher;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "academicRecord")
	@Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN })
	private Set<Coursing> coursings;

	@Column(name = "FECHA", nullable = false)
	private Date date;

	@Override
	public String[] getExcludedFields() {
		return new String[] { "subject", "teacher", "coursings", "date" };
	}

	public Date getDate() {
		return date;
	}

	public String getFormattedDate() {
		return new SimpleDateFormat("dd/MM/yyyy").format(date);
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Subject getSubject() {
		return subject;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public Set<Coursing> getCoursings() {
		return coursings;
	}

	public void setCoursings(Set<Coursing> coursings) {
		this.coursings = coursings;
	}
}
